import pandas as pd
import matplotlib.pyplot as plt
import matplotlib

matplotlib.rcParams['font.family'] = 'SimHei'

# 读取数据
df = pd.read_csv('data_100.csv', encoding='utf-8')
df['开奖日期'] = pd.to_datetime(df['开奖日期'])
df['销售额'] = pd.to_numeric(df['销售额'], errors='coerce')
df.dropna(subset=['销售额'], inplace=True)

# 按星期分组
groups = df.groupby('星期')

# 初始化统计容器
summary = {}

for weekday in ['星期一', '星期三', '星期六']:
    group = groups.get_group(weekday)

    summary[weekday] = {
        '期数': len(group),
        '总销售额': group['销售额'].sum(),
        '平均销售额': group['销售额'].mean()
    }

# 输出销售额对比
for weekday in summary:
    print(f"\n {weekday}：")
    print(f"期数：{summary[weekday]['期数']}期")
    print(f"总销售额：{summary[weekday]['总销售额']:,.0f} 元")
    print(f"平均销售额：{summary[weekday]['平均销售额']:,.0f} 元")

# 可视化销售额对比
weekdays = list(summary.keys())
avg_sales = [summary[w]['平均销售额'] for w in weekdays]

plt.figure(figsize=(8, 4))
plt.bar(weekdays, avg_sales, color=['skyblue', 'orange', 'lightgreen'])
plt.title('不同开奖日的平均销售额对比')
plt.ylabel('平均销售额（元）')
plt.grid(True)
plt.tight_layout()
plt.show()